namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class PushButtonFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<PushButton>()
                .DerivesFrom<Button>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("button")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            PushButton expected = new PushButton(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                Disabled = true,
                Language = "fr",
                TabIndex = 1,
                Title = "title",
                Value = "value"
            };

            string xml = "<button id='id' class='class' lang='fr' title='title' name='id' accesskey='a' tabindex='1' disabled='disabled' type='button' value='value' />";
            PushButton actual = xml.Deserialize<PushButton>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<button type='button' />".Deserialize<PushButton>());
        }

        [Fact]
        public void serialize()
        {
            PushButton obj = new PushButton(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                Disabled = true,
                Language = "fr",
                TabIndex = 1,
                Title = "title",
                Value = "value"
            };

            string xpath = "1=count(/button[@id='id'][@class='class'][@lang='fr'][@title='title'][@name='id'][@tabindex='1'][@disabled='disabled'][@accesskey='a'][@type='button'][@value='value'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new PushButton());
        }

        [Fact]
        public void ctor_Name()
        {
            Assert.NotNull(new PushButton(new Name("id")));
        }

        [Fact]
        public void ctor_NameNull()
        {
            Assert.NotNull(new PushButton(null));
        }

        [Fact]
        public void prop_Type()
        {
            Assert.True(new PropertyExpectations(typeof(PushButton).GetProperty("Type"))
                .DefaultValueIs("button")
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            PushButton expected = new PushButton(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                Disabled = true,
                Language = "fr",
                TabIndex = 1,
                Title = "title",
                Value = "value"
            };

            string xml = "<button id='id' class='class' lang='fr' title='title' name='id' accesskey='a' tabindex='1' disabled='disabled' type='button' value='value' />";
            PushButton actual = new PushButton().Deserialize("button", "button", xml) as PushButton;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}